package online.westonline.com.westonline.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import online.westonline.com.westonline.R;

/**
 * popwindow适配器
 * Created by xiatao on 2018/6/14.
 */

public class PopWindowTypeAdpter extends RecyclerView.Adapter<PopWindowTypeAdpter.PopWindowViewHolder> {
    private List<String> arrays = new ArrayList<>();
    private itemClick click;

    public void setClick(itemClick click) {
        this.click = click;
    }
    public void setArrays(List<String> arrays) {
        this.arrays = arrays;
    }

    @NonNull
    @Override
    public PopWindowViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.node_type_item, parent, false);
        return new PopWindowViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull PopWindowViewHolder holder, int position) {
        holder.tvTypePop.setText(arrays.get(position));
    }

    @Override
    public int getItemCount() {
        return arrays.size();
    }

    class PopWindowViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_type_pop)
        TextView tvTypePop;
        public PopWindowViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
            itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (click!=null)
                    {
                        click.click(getLayoutPosition(),arrays.get(getLayoutPosition()));
                    }
                }
            });
        }
    }

    public interface itemClick
    {
        void click(int pos, String type);
    }
}
